package ltd.hxya.novel.common.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletRequest;

public class ServerUtils {

    //从当前请求中根据key值获取参数
    public static Object getParamBykey(String key) {
        return getRequest().getParameter(key);

    }

    /**
     * 获取当前请求
     * @return
     */
    public static ServletRequest getRequest(){
        return getRequestAttributes().getRequest();
    }

    /**
     * 获取请求域
     * @return
     */
    public static ServletRequestAttributes getRequestAttributes(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        return (ServletRequestAttributes) requestAttributes;
    }
}
